//
//  FLLMethodViewController.m
//  FLLGodOfCooking
//
//  Created by LL.F on 16/9/13.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLMethodViewController.h"
#import "FLLMacro.h"
#import "FLLMethodModel.h"
#import "MethodData.h"
#import "MethodStep.h"
#import "MethodTags_Info.h"
#import "FLLMethodTableViewCell.h"
@interface FLLMethodViewController ()<UITableViewDelegate, UITableViewDataSource>


@end

@implementation FLLMethodViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
   
    [self createMethodTableView];
    

}
- (void)createMethodTableView
{

    self.methodTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 95 * kHeightScale) style:UITableViewStylePlain];
    self.methodTableView.delegate = self;
    self.methodTableView.dataSource = self;
    self.methodTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.methodTableView.bounces = NO;
    [self.methodTableView registerNib:[UINib nibWithNibName:@"FLLMethodTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"methodTableCell"];
    [self.view addSubview:_methodTableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return _stepArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    FLLMethodTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"methodTableCell"];
    [cell.stepImageView sd_setImageWithURL:[NSURL URLWithString:_stepArray[indexPath.row].dishes_step_image] placeholderImage:[UIImage new] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
   
    cell.methodLabel.text = [NSString stringWithFormat:@"%zd %@", indexPath.row + 1, _stepArray[indexPath.row].dishes_step_desc];
    /** 关键字高亮*/
    NSString *highLightString = [NSString stringWithFormat:@"%zd", indexPath.row + 1];
    NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc]initWithString:cell.methodLabel.text];
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:13 * kWidthScale], NSForegroundColorAttributeName : FLLOrangeColor};
    NSRange range = [cell.methodLabel.text rangeOfString:highLightString];
    [attribut addAttributes:dic range:range];
    cell.methodLabel.attributedText = attribut;
    cell.methodLabel.font = [UIFont systemFontOfSize:13 *kWidthScale];
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return SCREEN_WIDTH * 2 / 3.0 + [GetHeightTools heightWith:_stepArray[indexPath.row].dishes_step_desc];
    
}

- (void)setStepArray:(NSMutableArray<MethodStep *> *)stepArray
{

    _stepArray = stepArray;
    [self.methodTableView reloadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
